﻿using System.Linq;
using AB.ServiceDirectory.Commons.DataFilters;
using AB.ServiceDirectory.Dao;
using AB.ServiceDirectory.Entities;

namespace AB.ServiceDirectory.BO
{
    /// <summary>
    /// DepartmentBO
    /// </summary>
    public sealed class DepartmentBO
    {
        private static readonly DepartmentDao Dao = new DepartmentDao();

        /// <summary>
        /// Prevents a default instance of the <see cref="DepartmentBO"/> class from being created.
        /// </summary>
        private DepartmentBO()
        {
        }

        /// <summary>
        /// Gets the department.
        /// </summary>
        /// <param name="filter">The filter.</param>
        /// <param name="sortType">Type of the sort.</param>
        /// <param name="startRowIndex">Start index of the row.</param>
        /// <param name="maxRows">The max rows.</param>
        /// <returns></returns>
        public static IQueryable<Department> GetDepartment(DepartmentFilter filter, string sortType, int startRowIndex,
                                                           int maxRows)
        {
            return Dao.GetList(filter, sortType, startRowIndex, maxRows);
        }

        /// <summary>
        /// Gets the department by id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public static Department GetDepartmentById(int id)
        {
            return Dao.GetDepartmentId(id);
        }

        /// <summary>
        /// Gets the department count.
        /// </summary>
        /// <param name="filter">The filter.</param>
        /// <returns></returns>
        public static int GetDepartmentCount(DepartmentFilter filter)
        {
            return Dao.GetListCount(filter);
        }

        /// <summary>
        /// Inserts the department.
        /// </summary>
        /// <param name="department">The department.</param>
        /// <returns></returns>
        public static bool InsertDepartment(Department department)
        {
            return Dao.AddDepartment(department);
        }

        /// <summary>
        /// Edits the department.
        /// </summary>
        /// <param name="department">The department.</param>
        /// <returns></returns>
        public static bool EditDepartment(Department department)
        {
            return Dao.EditDepartment(department);
        }

        /// <summary>
        /// Adds the department.
        /// </summary>
        /// <param name="newDepartment">The new department.</param>
        /// <returns></returns>
        public static bool AddDepartment(Department newDepartment)
        {
            return Dao.AddDepartment(newDepartment);
        }

        /// <summary>
        /// Checks the name of the department.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <returns></returns>
        public static bool CheckDepartmentName(string name)
        {
            return Dao.CheckDepartmentName(name);
        }

        /// <summary>
        /// Sets the department status.
        /// </summary>
        /// <param name="departmentId">The department id.</param>
        /// <param name="status">if set to <c>true</c> [status].</param>
        /// <returns></returns>
        public static bool SetDepartmentStatus(int departmentId, bool status)
        {
            return Dao.SetDepartmentStatus(departmentId, status);
        }
    }
}